﻿using System.Data.Common;
using System.Data.SqlClient;
using Zinnia.Kernel;
using Zinnia.Kernel.Core;
using Zinnia.Lite.Configs;

namespace Zinnia.Lite.Core.Imp.Mssql
{
    /// <summary>
    /// 数据库驱动
    /// </summary>
    public class MssqlDriver : IDriver
    {
        private readonly IEncryptService _encryptService;
        public MssqlDriver()
        {
            _encryptService = KernelService.DependencyInjectHub.Resolve<IEncryptService>();
        }

        public DbConnection GetDbConnection(StorageConfig config)
        {
            return new SqlConnection
            {
                ConnectionString = $"Data Source={config.DataSource}; Initial Catalog={config.InitialCatalog}; User ID={config.UserId}; Password={_encryptService.Decrypt(config.Password, "0845d1a5")}; MultipleActiveResultSets=True"
            };
        }
    }
}
